/**
 * @param {number[]} plants
 * @param {number} capacityA
 * @param {number} capacityB
 * @return {number}
 */
var minimumRefill = function (plants, capacityA, capacityB) {
    let left = 0, right = plants.length - 1
    let res = 0, ca = capacityA, cb = capacityB
    while (left < right) {
        if (ca >= left) ca -= plants[left]
        else { res++; ca = capacityA - plants[left] }
        if(cb >= right) cb -= plants[right]
        else {
            res++;
            cb = capacityB - plants[right]
        }
        left++
        right--
    }
    if(left === right && Math.max(ca, cb) < plants[left]) {
        res++
    }
    return res
};